package com.hsjk.szwj.module.smedia.controller.admin.mediaUpload;

import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.module.smedia.controller.admin.mediaUpload.vo.CreateUploadStreamReqVO;
import com.hsjk.szwj.module.smedia.controller.admin.mediaUpload.vo.CreateUploadStreamRespVO;
import com.hsjk.szwj.module.smedia.controller.admin.mediaUpload.vo.RegisterMediaStreamReqVO;
import com.hsjk.szwj.module.smedia.controller.admin.mediaUpload.vo.RegisterMediaStreamRespVO;
import com.hsjk.szwj.module.smedia.service.mediaUpload.IMediaUpload;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/07/23 19:21
 **/
@Tag(name = "管理后台 - 媒资上传")
@RestController
@RequestMapping("/system/media-upload")
@Validated
public class MediaUploadController {
    @Resource
    private IMediaUpload mediaUpload;

    @PostMapping("/create-upload-stream")
    @Operation(summary = "获取媒体流上传地址和凭证")
    @PreAuthorize("@ss.hasPermission('system:media-upload:create')")
    public CommonResult<CreateUploadStreamRespVO> createUploadStream(@Valid @RequestBody CreateUploadStreamReqVO reqVO) {
        return success(mediaUpload.createUploadStream(reqVO));
    }

    @PostMapping("/register-media-stream")
    @Operation(summary = "注册媒体流")
    @PreAuthorize("@ss.hasPermission('system:media-upload:create')")
    public CommonResult<RegisterMediaStreamRespVO> registerMediaStream(@Valid @RequestBody RegisterMediaStreamReqVO reqVO) {
        return success(mediaUpload.registerMediaStream(reqVO));
    }
}
